package com.filemanager;
import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * Created by IntelliJ IDEA.
 * User: Anna.Bulenkova
 * Date: 26.10.11
 * Time: 18:33
**/
public class FileClient extends Thread {
    private Socket mySocket;

    FileClient(Socket socket) {
        this.mySocket = socket;
    }


    public void run() {

        try
        {
            BufferedReader in = new BufferedReader(new InputStreamReader(mySocket.getInputStream()));
            BufferedOutputStream outputStream = new BufferedOutputStream(mySocket.getOutputStream());
            PrintWriter out = new PrintWriter(outputStream, true);
            String fromServer;
            JavaToXMLUsingJAXB.sendXML(out);

            while ((fromServer = in.readLine()) != null) {
                System.out.println("get someth form server" + fromServer);
            }

            in.close();
            out.close();
            mySocket.close();
        }
            catch (UnknownHostException e) {
            System.err.println("Don't know about hos");
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection");
            System.exit(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException {
        String fromUser;
        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        Socket speaker = new Socket("localhost", 3333);


        new FileClient(speaker).start();




    }


}
